const jsonwebtoken = require("jsonwebtoken");
const jwt = require("koa-jwt");
const { secret } = require("../config");
const Router = require("koa-router");
const router = new Router({ prefix: "/evil/auth" });  // 路由前缀
const {
	find,
	findById,
	create,
	checkOwner,
	update,
	delete: del,
	login,
	findByToken,
	refreshToken
} = require("../controllers/auth.js");  // 控制器方法

const auth = jwt({ secret });  // jwt鉴权

router.get("/list", find);  // 获取用户列表

router.post("/create", create);  // 创建用户

router.post('/findByToken',findByToken)

router.post('/refreshToken',refreshToken)

router.get("/getById/:id", findById);  // 获取特定用户

router.patch("/update/:id",auth, checkOwner, update);  // 更新用户信息

router.delete("/del/:id",auth, checkOwner, del);  // 删除用户

router.post("/login", login);  // 用户登录

module.exports = router;
